package done.myra.excercise.ch9;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test04 {

	public static void main(String[] args) {
		test02();
	}

	private static void test02() {

		// 北京时间
		Date dateBJ = new Date();
		// 巴黎时间
		Date dateParis = new Date();
		// 美国时间
		Date dateUSA = new Date();
		//日历对象
		Calendar cal = Calendar.getInstance();

		//输入时间
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入北京时间的年份");
		int year = sc.nextInt();
		System.out.println("请输入北京时间的月份");
		int month =sc.nextInt()-1;
		System.out.println("请输入北京时间的日期");
		int day = sc.nextInt();
		System.out.println("请输入北京时间的小时");
		int hour = sc.nextInt();
		System.out.println("请输入北京时间的分钟");
		int minute = sc.nextInt();
		System.out.println("请输入北京时间的秒钟");
		int second = sc.nextInt();
		//设置北京时间
		cal.set(year, month, day, hour, minute, second);
		dateBJ = cal.getTime();
		
		
		//设置巴黎时间
		int dayParis = day;
		int hourParis =hour;
		if(hourParis-7<0) {
			dayParis--;
			hourParis=hourParis-7+24;
		}else {
			hourParis -= 7;
		}
		cal.set(year, month, dayParis, hourParis, minute, second);
		dateParis = cal.getTime();
		
		
		//设置美国时间
		int dayUSA = day;
		int hourUSA =hour;
		if(hourUSA-12<0) {
			dayUSA--;
			hourUSA=hourUSA-12+24;
		}else {
			hourUSA-=12;
		}
		cal.set(year, month, dayUSA, hourUSA, minute, second);
		dateUSA = cal.getTime();
		

		System.out.println("北京时间："+dateBJ);
		System.out.println("巴黎时间"+dateParis);
		System.out.println("美国时间"+dateUSA);

	}

	private static Date string2date(String str, String strFormat) {
		// 结果日期
		Date date = null;

		if (strFormat == null || strFormat == "") {
			strFormat = "yyyy年MM月dd日";
		}

		SimpleDateFormat sdf = new SimpleDateFormat(strFormat);

		if (str != null && str.length() > 0) {
			try {
				date = sdf.parse(str);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return date;
	}

	private static String date2string(Date date, String dateFormat) {
		// 结果字符串
		String str;
		// 判断date是否为空
		if (date == null) {
			date = new Date();
		}
		if (dateFormat == null || dateFormat == "") {
			dateFormat = "当前时间：yyyy-MM-dd HH:mm:ss";
		}

		// simpleDateFormat
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		str = sdf.format(date);

		return str;

	}

}
